using UnityEngine;
using System.Collections;

public class MoveOnPlanet : MonoBehaviour {

    public Transform    _planet;
    public float        _mass = 1.0f;
    public float        _gravity = 9.81f;

    private Vector3     _momentum;
    private Vector3     _gravityDirection;

	// Use this for initialization
	void Start () {
        _momentum = new Vector3(0.0f, 0.0f, 0.0f);
	}
	
	// Update is called once per frame
	void FixedUpdate () {
        CharacterController characterController = (CharacterController)GetComponent("CharacterController");

        _gravityDirection = Vector3.Normalize(_planet.GetChild(0).transform.position - transform.position);
        transform.LookAt(_planet.GetChild(0));
        //Vector3 force = (_gravityDirection * _gravity) * _mass;
        //_momentum += force * Time.deltaTime;
        //Vector3 velocity = _momentum / _mass;
        
        //if ( !characterController.isGrounded )

        // Move forward / backward
        Vector3 leftRight = GameObject.Find("CharacterCamera").transform.TransformDirection(Vector3.right);
        //Vector3 leftRight = transform.TransformDirection(Vector3.right);
        float curSpeed = 3.0f * Input.GetAxis("Horizontal");

        characterController.Move(_gravityDirection * _gravity *  Time.deltaTime);
        // characterController.Move(leftRight * curSpeed * Time.deltaTime);
	}
}
